package com.easybuilder.core.dictionary.service.impl;

import com.easybuilder.common.utils.RedisUtil;
import com.easybuilder.core.dictionary.dao.SysDictionaryDao;
import com.easybuilder.core.dictionary.dao.SysDictionaryItemDao;
import com.easybuilder.core.dictionary.service.DictionaryService;
import com.easybuilder.core.dictionary.view.DictionaryView;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author ZXS
 * @version 1.0
 * @description 类
 * @date 2021-8-29 17:14
 */
@Service
public class DictionaryServiceImpl implements DictionaryService {
    @Autowired
    private SysDictionaryDao dictionaryDao;
    @Autowired
    private SysDictionaryItemDao dictionaryItemDao;

    @Override
    public List<DictionaryView> getDictionaryView(Long dict_id) {

        // 1.尝试从缓存中获取数据
        String redisKey = "DICTIONARY_" + dict_id;
        List<DictionaryView> cache = RedisUtil.getValue(redisKey, List.class);
        if (cache == null) {
            cache = dictionaryItemDao.getDictionaryView(dict_id);
            // 保存缓存数据
            RedisUtil.setValue(redisKey, cache);
        }
        return cache;
    }
}
